package com.zeta.eduservice.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zeta.commonutils.R;
import com.zeta.eduservice.entity.EduAcademy;
import com.zeta.eduservice.entity.EduStudent;
import com.zeta.eduservice.entity.vo.AcademyQuery;
import com.zeta.eduservice.entity.vo.AcademyVo;
import com.zeta.eduservice.entity.vo.StudentQuery;
import com.zeta.eduservice.service.EduAcademyService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * <p>
 * 学院 前端控制器
 * </p>
 *
 * @author zeta
 * @since 2020-08-17
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/edu_academy")
public class EduAcademyController {
	@Autowired
	private EduAcademyService AcademyService;

	@ApiOperation("增加学院")
	@PostMapping("")
	public R add(@RequestBody EduAcademy academy) {
		boolean flag = AcademyService.save(academy);
		if(flag)
			return R.ok();
		else
			return R.error();
	}
	@ApiOperation(value = "根据ID删除学院")
	@DeleteMapping("{id}")
	public R remove(@PathVariable String id) {
		boolean flag = AcademyService.removeById1(id);
		 if(flag){
		        return R.ok();
		    }else{
		        return R.error().message("删除失败");
		    }
	}

	@ApiOperation(value = "根据ID修改学院")
	@PutMapping("")
	public R updateById(
	    @ApiParam(name = "academy", value = "学院对象", required = true)
	    @RequestBody EduAcademy academy){
		AcademyService.updateById(academy);
	    return R.ok();
	}
	
	
	@ApiOperation("查询学院")
	@GetMapping("{id}")
	public R find(@PathVariable String id) {
		EduAcademy byId = AcademyService.getById(id);
		return R.ok().data("academy", byId);
	}
	@ApiOperation("查询所有学院")//和班级
	@GetMapping("/findAll")
	public R findAll() {
		List<AcademyVo> list = AcademyService.findList();
		return R.ok().data("academys", list);

	}
	
	@GetMapping("/getAll")
	public R getAllAca() {
		List<EduAcademy> list = AcademyService.list(null);
		return R.ok().data("acaList",list);
	}
	
}

